<?php

class PostDisplayer {
	public static function displayPost($post, $loggedUserName, $user) { 
	//$user = true jesli ma wyswietlic psot na stronie usera, false jesli na glwonej lub w subskrypcjach
	?> 
		<div class="post <?php echo $user ? 'user' : 'default' ?>">
			<div class="icon <?php echo $user  ? 'classic' : 'avatar' ?>">
			
				<img src="<?php URI::theUrl(); echo $user  ? 'content/icos/'.$post->getType().'.png' : $post->getUser()->getAvatar(); ?>" />
				
			</div>
			<div class="content-wrapper <?php echo $user ? 'user' : 'default' ?>">
				<div class="content">
					<?php self::displayPostContent($post); ?>
				</div>
				<div class="tags">
					<?php 
						
					?>
					<span class="label">
						<?php $tags = $post->getTags(); if (isset($tags) && !empty($tags)) echo 'Tagi:';?>
					</span>
					<span class="content">
						<?php 							
							$tags=$post->getTags();
							if (isset($tags)) {
								foreach ($tags as $t) {
									echo $t.' ';
								}
							}
						?>
					</span>
					<?php //isset($tags) ?>
				</div>
				<div class="repost-wrapper">
					<?php if($post->isRepost()): ?>
						<div id="reposted-from">repost from 
						<?php 
							$l=$post->getOriginalPostOwner();							
							echo '<a href="?user='.$l->getLogin().'" />';
							echo '<img src="'.$l->getAvatar().'" height="15px" width="15"/>';
							echo ''.$l->getLogin();
							echo '</a>';
						?>  
						<?php 
							$l=$post->getPrevPostOwner();
							if ($l->getId()!=$post->getOriginalPostOwner()->getId()){
								echo 'via	';
								echo '<a href="?user='.$l->getLogin().'" />';
								echo '<img src="'.$l->getAvatar().'" height="15px" width="15"/>';
								echo ''.$l->getLogin();
								echo '</a>';
							}							
						?>
						</div>
					<?php else: ?>
						<?php if($post->getListOfReposts()): ?>	
						<div id="reposted-by">reposted by
						<?php
							if ($post->getListOfReposts()) {
								$list=$post->getListOfReposts();								
								foreach($list as $l) {
									echo '<a href="?user='.$l->getLogin().'" />';
									echo '<img src="'.$l->getAvatar().'" height="15px" width="15"/>';
									echo ''.$l->getLogin();
									echo '</a>';									
								} 
							}
						?> 						
						</div>
						<?php endif;?>
					<?php endif; ?>
				</div>
				<div class="actions-wrapper">
					<?php if($loggedUserName == $post->getUser()->getLogin()): ?>
						<!--<a href="<?php URI::theUrl('edit', $loggedUserName, null, $post->getId()) ?>"><img src="<?php URI::theUrl() ?>/content/images/edit.png" /></a>-->
						<a href="<?php URI::theUrl('delete', $loggedUserName, null, $post->getId()) ?>"><img src="<?php URI::theUrl() ?>/content/images/delete.png" /></a>
					<?php elseif($loggedUserName != null): ?>
						<a href="<?php URI::theUrl('repost', $loggedUserName, null, $post->getId()) ?>"><img src="<?php URI::theUrl() ?>/content/images/repost.png" /></a>
					<?php endif; ?>
				</div>
			</div>
		</div>
	<?php }
	
	private static function displayPostContent($post) { 
		switch($post->getType()) {
			case Post::TYPE_IMAGE:
				self::displayImage($post);
				break;
			case Post::TYPE_MOVIE:
				self::displayMovie($post);
				break;
			case Post::TYPE_COMMENT:
				self::displayComment($post);
				break;
			case Post::TYPE_QUOTE:
				self::displayQuote($post);
				break;
			case Post::TYPE_ARTICLE:
				self::displayArticle($post);
				break;
		}
	}
	
	private static function displayImage($post) { 
		if($post->getShowTitle()): ?>
			<div class="title"><h2><?php echo $post->getTitle(); ?></h2></div>
		<?php endif; ?>
		<div class="image-wrapper"><img src="<?php echo $post->getContent(); ?>" alt="<?php echo $post->getTitle(); ?>" <?php 
			if($post->getImage())
				echo 'onclick="showFullSizeImage('.$post->getImage().')"';
		?>/></div>
		<div class="description"><?php echo $post->getDescription(); ?></div>
	<?php }
	
	private static function displayMovie($post) { 
		if($post->getShowTitle()): ?>
			<div class="title"><h2><?php echo $post->getTitle(); ?></h2></div>
		<?php endif; ?>
		<div class="movie-wrapper"><?php echo $post->getContent(); ?></div>
		<div class="description"><?php echo $post->getDescription(); ?></div>
	<?php }

	private static function displayComment($post) { ?>
		<div class="comment-wrapper"><?php echo $post->getContent(); ?></div>
	<?php }

	private static function displayQuote($post) { ?>
		<div class="quote-wrapper">"<?php echo $post->getContent(); ?>"</div>
	<?php }	
	
	private static function displayArticle($post) { ?>
		<div class="article-wrapper"><?php echo $post->getContent(); ?></div>
	<?php }	
}
?>